<?php
class C_Athorization extends MVC_Controller_Base {

    public function index() {
        $this->_prepareIndex();
        $this->_addView('Forms_Athorization');
    }


    public function _postIndex() {
        $objUser = $this->_prepareIndex();

        $strLogin    = $this->_POST_item('login');
        $strPassword = $this->_POST_Item('password');

        if (!$objUser->isCorrectAuthorizationData($strLogin, $strPassword)) {
            $this->_addView('Forms_Athorization');
            return ;
        }

        $this->_SESSION()->set('login', $strLogin);
        $this->_SESSION()->set('password', md5($strPassword));

        $this->_addView('Athorization_Login');

        $this->_addHookAdd ('js', 'JS_GoToMainPage')
             ->_addVariable('iTime', 5);
    }


    private function _prepareIndex () {
        /* @var $objUser M_ACL_User */
        $objUser = $this->_getModel('ACL_User');
        if ($objUser->getLogin() != '@guest') {
            //$this->_redirect('/');
        }

        return $objUser;
    }


    public function logout () {
        $this->_SESSION()->delete('login');
        $this->_SESSION()->delete('password');

        $this->_addView('Athorization_Logout');
    }


    public function userdata () {
        $this->_addView('Athorization_UserData')
             ->_addVariable('login', $this->_getModel('ACL_User')->getLogin());
    }
}